<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
<!--2s后执行populate方法-->
    function f() {
        window.setTimeout("populate()", 2000);
    }

    function populate() {
        document.f1.t1.value = "populated";
        document.getElementById("id1").innerHTML = "<div id='id2'>id 2</div>"
    }
</script>
<form name="f1">
    <input type="text" , name="t1">
    <input type="button" value="Click me" onclick="f()" id="btn">
    <div id="id1">
    </div>
</form>
</body>
</html>